<?php
// List of already created batches
if (count($this->data->batchList) > 0) {
    
    /*
    $elb = new EntityListBuilder('seminarBatch', $this->data->batchList);
    $elb->text('code')->noLink();
    $elb->text('batch_type_code');
    $elb->date('begin_date');
    $elb->time('begin_time');
    $elb->date('end_date');
    $elb->time('end_time');
    $elb->text('description');
    $elb->text('')->valueFunction('deleteLink');
    html::anchor('admin/seminarWizard/seminarBatchDelete?index=' . $index, 'smazat', array('onclick'=>'return confirmDeletion()', 'title'=>text::get('button.delete-title')));
    $elb->write();
    */

    echo '<h3>' . text::getEscaped('seminarWizard.seminarBatch-alreadyCreatedList') . '</h3>';
    echo '<ul id="seminarBatchList" class="wizardEntityList">';
    foreach ($this->data->batchList as $index => $batch) {
        echo '<li>' .
             '<span class="entityName hasTooltip" onclick="$(this.parentNode).find(\'.createdEntity\').slideToggle()">' . $batch['name'] . '</span>&nbsp;' .
             html::anchor('admin/seminarWizard/seminarBatchDelete?index=' . $index, 'smazat', array('onclick'=>'return confirmDeletion()', 'title'=>text::get('button.delete-title')));
        echo '<div class="tooltip">';
        echo '<p><b>' . $batch['name'] . '</b> ' . $batch['batch_type']['name'] . '</p>';
        echo '<p>' . format::dateAndTime($batch['begin_date'], $batch['begin_time']) .
             ' - ' .
             format::dateAndTime($batch['end_date'], $batch['end_time']) . '</p>';
        $desc = $batch['description'];
        if ($desc) {
            echo '<p>' . $desc . '</p>';
        }
        echo '</div>';
        echo '</li>';
    }
    echo '</ul>';
    ?>

    <script type="text/javascript">
        $(document).ready(function() {
            $groupList = $("#seminarBatchList > li > .entityName").each(function() {
                $(this).tooltip({
                    bodyHandler: function() {
                        return $(this).parent().find("div.createdEntity").html();
                    }
                });
            });
        });

        function openShortProgramBatchesDialog() {
            new Dialog()
            $('#shortProgramBatchForm').dialog();
        }
    </script>
    <?php
}

echo '<h3>' . text::getEscaped('seminarWizard.seminarBatch-createForm') . '</h3>';

$fb = new FormBuilder('seminarBatch', $seminarBatch);
$fb->setAction('/admin/seminarWizard/seminarBatchAdd');
$fb->text('name')->required();
$fb->date('begin_date')->required();
$fb->time('begin_time')->required();
$fb->date('end_date')->required();
$fb->time('end_time')->required();
$fb->comboBox('batch_type_code', $seminarBatchTypeOptions)->required()->hint();
$fb->textarea('description');
$fb->button('submit', 'seminarWizard.seminarBatch-createButton')->styleClass('primaryAction');
$fb->write();
